package com.wlscale.roadsystem.modular.setting;

import android.util.TypedValue;
import android.view.View;
import android.widget.Button;

import com.easy.component.component.header.EasyHeaderBuilder;
import com.wlscale.roadsystem.R;
import com.wlscale.roadsystem.base.LZBaseActivity;
import com.wlscale.roadsystem.modular.setting.adapter.UserMangerAdapter;
import com.wlscale.roadsystem.wiget.AddOperatorDialog;
import com.wlscale.roadsystem.wiget.ChangePasswordDialog;
import com.wlscale.roadsystem.wiget.EditOperatorDialog;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenu;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuCreator;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuItem;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuListView;

/**
 * 用户管理
 */
public class UserManagementActivity extends LZBaseActivity implements View.OnClickListener {
    /**
     *
     */
    private EasyHeaderBuilder easyHeaderBuilder;
    /**
     *
     */
    private UserMangerAdapter userMangerAdapter;
    /**
     *
     */
    private SwipeMenuListView recyclerView;
    /**
     * 添加操作员
     */
    private Button btn_add_operator;

    @Override
    public void initlayoutResID() {
        setContentView(R.layout.activity_operator_manage);
    }

    @Override
    public void initBundle() {

    }

    @Override
    public void initView() {
        btn_add_operator = findViewById(R.id.btn_add_operator);
        btn_add_operator.setOnClickListener(this);

        recyclerView = findViewById(R.id.rv_operatorListView);
        userMangerAdapter = new UserMangerAdapter(this);
        recyclerView.setAdapter(userMangerAdapter);
        SwipeMenuCreator creator = new SwipeMenuCreator() {

            @Override
            public void create(SwipeMenu menu) {
                createMenu(menu);
            }
        };
        recyclerView.setMenuCreator(creator);
        recyclerView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
                switch (index) {
                    case 0:
                        ChangePasswordDialog dialog = new ChangePasswordDialog.Builder().setContext(UserManagementActivity.this).setOnClickLister(new ChangePasswordDialog.OnClickLister() {
                            @Override
                            public void onClickLister(String locAddress) {

                            }
                        }).builder();
                        dialog.show();
                        break;
                    case 1:
                        EditOperatorDialog editOperatorDialog = new EditOperatorDialog.Builder().setContext(UserManagementActivity.this).setOnClickLister(new EditOperatorDialog.OnClickLister() {
                            @Override
                            public void onClickLister(String locAddress) {

                            }
                        }).builder();
                        editOperatorDialog.show();
                        break;
                    case 2:
                        showAlert("温馨提示：", "你准备删除操作员ID为：xxx，的操作员吗？", "确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        }, "取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        });
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public void initHeader() {
        easyHeaderBuilder = new EasyHeaderBuilder(this);
        easyHeaderBuilder.addLeftImageBackView();
        easyHeaderBuilder.setTitle("用户管理");
        easyHeaderBuilder.addLeftImageBackListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishActivity();
            }
        });
    }

    @Override
    public void initLoadingView() {

    }

    @Override
    public void initData() {

    }

    private void createMenu(SwipeMenu menu) {

        SwipeMenuItem item0 = new SwipeMenuItem(this);
        item0.setBackground(R.color.orange);
        item0.setWidth(dp2px(100));
        item0.setIcon(R.mipmap.ic_change_pass);
        menu.addMenuItem(item0);

        SwipeMenuItem item1 = new SwipeMenuItem(this);
        item1.setBackground(R.color.ksw_md_solid_checked);
        item1.setWidth(dp2px(100));
        item1.setIcon(R.mipmap.ic_edit);
        menu.addMenuItem(item1);

        SwipeMenuItem item2 = new SwipeMenuItem(this);
        item2.setBackground(R.color.button_red_disabled_edge);
        item2.setWidth(dp2px(100));
        item2.setIcon(R.mipmap.ic_delete);
        menu.addMenuItem(item2);
    }

    private int dp2px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_add_operator:
                AddOperatorDialog dialog = new AddOperatorDialog.Builder().setContext(this).setOnClickLister(new AddOperatorDialog.OnClickLister() {
                    @Override
                    public void onClickLister(String locAddress) {

                    }
                }).builder();
                dialog.show();
                break;
        }
    }
}
